﻿using AttributeRouting.Web.Http;
using ETA.Entity;
using ETA.IService;
using ETA.WebAPI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace ETA.WebAPI.Controllers
{
    public class FranchiseController : ApiController
    {
        private static IJoinApplyFormService _IJoinApplyFormService { set; get; }
        public FranchiseController(IJoinApplyFormService IJoinApplyFormService)
        {
            _IJoinApplyFormService = IJoinApplyFormService;
        }


        [GET("Franchise")]
        public ApiResDTO GetFranchise([FromUri]FranchiseDTO modelDto)
        {
            var res = new ApiResDTO();

            if (ModelState.IsValid)
            {
                var model = new JoinApplyForm
                {
                    CompanyName = modelDto.CompanyName,
                    Telephone = modelDto.Tel,
                    Mobile = modelDto.Phone,
                    Email = modelDto.Email,
                    ContactPerson = modelDto.Contact,
                    JoinApplyType = byte.Parse(modelDto.Type)
                };
                var createFres = _IJoinApplyFormService.CreateJoinApplyForm(new CreateJoinApplyFormRequest
                {
                    JoinApplyForm = model
                });

                if (createFres.Result.IsSuccess)
                {
                    res.Result = ResultEnum.Success;
                }
                else
                {
                    res.Result = ResultEnum.Fail;
                    res.ResultDesc = createFres.Result.ErrMessage;
                }
            }
            return res;
        }

    }
}
